﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace RoguelikeUIWPF
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private Renderer _renderer;
        public MainWindow()
        {
            InitializeComponent();

            this.KeyDown += new KeyEventHandler(OnButtonKeyDown);
            _renderer = new Renderer(paintCanvas);
            paintCanvas.Width = _renderer.WidthInPixels;
            paintCanvas.Height = _renderer.HeightInPixels;
            RoguelikeLib.Game.Renderer = _renderer;
            RoguelikeLib.Game.Start();
        }

        private void OnButtonKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Escape)
                Application.Current.Shutdown();
            else if (e.Key == Key.R)
                RoguelikeLib.Game.Start();
            else if (e.Key == Key.D)
                RoguelikeLib.Game.Debug();
            else
            {
                var a = new Stopwatch();
                a.Start();
                _renderer.UpdateGrid();

                a.Stop();
                Console.WriteLine("Updated in {0}", a.ElapsedMilliseconds);
            }

        }

    }
}
